#ifndef IPA2_H
#define IPA2_H

#include <QMainWindow>
#include <QButtonGroup>
#include <QGraphicsScene>
#include <QPen>
#include <QHoverEvent>
#include <QFileDialog>
#include <fstream>
#include <QMessageBox>

#include "serializedshape.h"

#ifndef SAVE
#define SAVE 1
#endif

#ifndef DISCARD
#define DISCARD 2
#endif

#ifndef CANCEL
#define CANCEL 3
#endif

#ifndef SHAPE_SIZE
#define SHAPE_SIZE 50
#endif

typedef int NoColorSelectedException;
typedef int UnknownTypeException;
typedef int UnknownReturnCodeException;

namespace Ui {
    class IPA2;
}

class IPA2 : public QMainWindow
{
    Q_OBJECT
    
    public:
        explicit IPA2(QWidget *parent = 0);
        ~IPA2();
        bool event(QEvent *event);

    private:
        Ui::IPA2 *ui;
        QButtonGroup *colorButtonGroup;
        QButtonGroup *shapeButtonGroup;
        QGraphicsScene scene;
        std::vector<QAbstractGraphicsShapeItem *> savedShapes;
        QAbstractGraphicsShapeItem *tempShape;
        const QBrush redBrush;
        const QBrush greenBrush;
        const QBrush blueBrush;
        const QPen redPen;
        const QPen greenPen;
        const QPen bluePen;
        bool mousePointerInWidget;
        bool drawingModified;
        QString filePath;

        //Functions
        std::string createSerializedShapeFileString();
        std::pair<const QBrush *, const QPen *> getBrushAndPen();
        void drawTriangle(int x, int y, const QBrush &brush, const QPen &pen);
        void drawCircle(int x, int y, const QBrush &brush, const QPen &pen);
        void drawSquare(int x, int y, const QBrush &brush, const QPen &pen);
        void draw(int x, int y);
        void drawSerializedShape(SerializedShape shape);
        void saveCurrentShape();
        int unsavedWarningBox();
        std::string buildCoordinatesString(int x, int y);

    private slots:
        void newFile();
        void openFile();
        void saveFile();
        void saveAsFile();
        void closeEvent(QCloseEvent *event);
        bool exit();
        void setCircleButton();
        void setSquareButton();
        void setTriangleButton();
        void setRedButton();
        void setGreenButton();
        void setBlueButton();
        void about();
};

#endif // IPA2_H
